/**
 * Author:yuiop
 * Date:2022/8/30 15:36
 */
package com.devops.admin.graphql;

import com.devops.admin.model.DOSMetrics;
import com.devops.admin.model.TableResult;
import com.devops.admin.service.DOSMetricsService;
import com.devops.admin.vo.DOSMetricsVo;
import com.devops.admin.vo.DOSPageVo;
import com.devops.common.annotation.DOSLog;
import com.devops.constant.DevOpsConstant;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsMutation;
import com.netflix.graphql.dgs.DgsQuery;
import com.netflix.graphql.dgs.InputArgument;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;


@DgsComponent
public class DOSMetricsDataFetcher {
    @Autowired
    DOSMetricsService dosMetricsService;

    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    @DOSLog(description = "添加一个指标")
    @DgsMutation
    public boolean addNewMetrics(@InputArgument  DOSMetricsVo dosMetricsVo){

        return dosMetricsService.saveMetrics(dosMetricsVo);
    }

    /**
     * @Author heyabo
     * @Description 更新指标
     * @Date 13:45 2022/8/31
     * @Param [dosMetricsVo]
     * @return boolean
     **/
    @DgsMutation
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    @DOSLog(description = "更新指标")
    public boolean updateMetrics(@InputArgument DOSMetricsVo dosMetricsVo){

        return dosMetricsService.updateMetrics(dosMetricsVo);
    }

    /**
     * @Author heyabo
     * @Description 删除指标信息
     * @Date 13:53 2022/8/31
     * @Param [metricsId]
     * @return boolean
     **/
    @DgsMutation
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    @DOSLog(description = "删除指标")
    public boolean deleteMetrics(Integer metricsId){

        return dosMetricsService.removeMetricsById(metricsId);
    }

    /**
     * @Author heyabo
     * @Description 分页查询指标
     * @Date 10:16 2022/8/31
     * @Param [dosMetricsVo]
     * @return com.devops.admin.model.TableResult<com.devops.admin.model.DOSMetrics>
     **/
    @DgsQuery
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    @DOSLog(description = "分页查询指标")
    public TableResult<DOSMetrics> getPageMetrics(@InputArgument DOSMetricsVo dosMetricsVo, @InputArgument DOSPageVo pageVo){

        return dosMetricsService.getPage(dosMetricsVo,pageVo);
    }
}
